<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="container">
        <!-- 存放表格 -->
        <table>
            <thead>
                <th>姓名</th>
                <th>年龄</th>
                <th>性别</th>
            </thead>
            <tbody>
                <tr>
                    <td>罗翔</td>
                    <td>50</td>
                    <td>男</td>
                </tr>
            </tbody>
        </table>

    </div>
    <script>
        var arr = [
            {
                name:"lx",
                age:50,
                gender:'男'
            },{
                name:'lyh',
                age:51,
                gender:'男'
            },{
                name:'zxm',
                age:33,
                gender:'男'
            },{
                name:'lw',
                age:30,
                gender:'女'
            }
        ]
        // 通过数据组装 对应的html字符串；然后再替换掉dom里的内容；
        var htmlstr = "";
        arr.forEach(function(item){
            htmlstr += `<tr><td>${item.name}</td><td>${item.age}</td><td>${item.gender}</td></tr>`
        })

        var tobodyEle = document.querySelector("tbody");
        tobodyEle.innerHTML = htmlstr;
    </script>
</body>
</html>